#include <linux/mm.h>
#include <linux/pagemap.h>

#include <asm/cacheflush.h>

void __flush_dcache_page(struct address_space *mapping, struct page *page)
{
	/*
	 * Writeback any data associated with the kernel mapping of this
	 * page.  This ensures that data in the physical page is mutually
	 * coherent with the kernels mapping.
	 */
// #ifdef CONFIG_HIGHMEM
	/*
	 * kmap_atomic() doesn't set the page virtual address, and
	 * kunmap_atomic() takes care of cache flushing already.
	 */
	// if (page_address(page))
// #endif
		__cpuc_flush_dcache_page(page_address(page));

	/*
	 * If this is a page cache page, and we have an aliasing VIPT cache,
	 * we only need to do one flush - which would be at the relevant
	 * userspace colour, which is congruent with page->index.
	 */
	// if (mapping && cache_is_vipt_aliasing())
	// 	flush_pfn_alias(page_to_pfn(page),
	// 			page->index << PAGE_CACHE_SHIFT);
}

void flush_dcache_page(struct page *page)
{
	struct address_space *mapping = page_mapping(page);

// #ifndef CONFIG_SMP
	// if (!PageHighMem(page) && mapping && !mapping_mapped(mapping))
	// 	set_bit(PG_dcache_dirty, &page->flags);
	// else
// #endif
	{
		__flush_dcache_page(mapping, page);
		// if (mapping && cache_is_vivt())
		// 	__flush_dcache_aliases(mapping, page);
		// else if (mapping)
			__flush_icache_all();
	}
}
